package cn.study.forkjointest.recursiveaction;

import cn.study.forkjointest.util.Utils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;


public class JdkTest {
    public static void main(String[] args){

        int[] arrayToSortByMergeSort = Utils.buildRandomIntArray(20_000_000);
        System.out.println("数组转list开始");
        long startTime = System.nanoTime();

        List<Integer> numberList = Arrays.stream(arrayToSortByMergeSort).boxed().collect(Collectors.toList());
        System.out.println("数据准备好了！！！:"+(System.nanoTime()-startTime)/(1000f*1000f));
        startTime = System.nanoTime();

        // 1、普通排序
        numberList.stream().sorted((a, b) -> a - b).collect(Collectors.toList());;
        System.out.println("普通排序:" + (System.nanoTime()-startTime)/(1000f*1000f));
        startTime = System.nanoTime();

        // 2、lamdba parallelStream 用到了forkJoin 归并排序
        numberList.parallelStream().sorted((a, b) -> a - b).collect(Collectors.toList());;
        System.out.println("lamdba parallelStream:"+(System.nanoTime()-startTime)/(1000f*1000f));
        startTime = System.nanoTime();

        // 3、parallelSort 用到了forkJoin 归并排序
        Arrays.parallelSort(arrayToSortByMergeSort);
        System.out.println("Arrays parallelSort:"+(System.nanoTime()-startTime)/(1000f*1000f));
    }
}